package com.cb.serviceimpl;

import com.cb.pojo.Employee;
import com.cb.dao.AdministratorDao;
import com.cb.service.AdministratorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.HashMap;

@Service
public class  AdministratorServiceImpl implements AdministratorService {

    @Autowired
    AdministratorDao administratorDao;
    @Override
    public String administratorLogin(HashMap json, HttpServletRequest request) {
        HttpSession sessoin=request.getSession();
        String username = String.valueOf(json.get("username"));
        String password = String.valueOf(json.get("password"));
        if(username!=null){
            Employee employee = administratorDao.login(username);
            if (employee==null){
                return "该用户不存在";
            }
            //System.out.println(employee.getPassword());
            if(password.equals(employee.getPassword())){
                sessoin.setAttribute("username",username);
                sessoin.setAttribute("password",password);
                sessoin.setAttribute("administratoryyid",employee.getYyid());
                return employee.getYyid();
            }
            else{
                return "密码错误";
            }
        }
        else{
            return "账号不能为空";
        }
    }

    @Override
    public String xianshi(HttpServletRequest request) {
        HttpSession sessoin=request.getSession();
        return (String)sessoin.getAttribute("username");
    }
}
